package com.example.arithmeticleetcode.leetcode.dec;

import java.util.ArrayList;
import java.util.List;

/**
 * @program: arithmetic-leetcode
 * @description:
 * @author: FangZhen
 * @create: 2020-12-07 10:35
 **/
public class Demo02 {

    private String[] strings = {"abc", "def", "ghi", "jkl", "mno", "pqrs", "tuv", "wxyz"};

    public List<String> letterCombinations(String digits) {
        if (digits == null) return null;
        List<String> list = new ArrayList<>();
        if (digits.length() == 0) return list;
        char[] chars = digits.toCharArray();
        char[] resultChar = new char[chars.length];
        dfs(0, chars, resultChar, list);
        return list;
    }

    private void dfs(int count, char[] chars, char[] resultChar, List<String> list) {
        if (count == chars.length) {
            String s = new String(resultChar);
            list.add(s);
            return;
        }

        String string = strings[chars[count] - '2'];
        for (int i = 0, len = string.length(); i < len; i++) {
            resultChar[count] = string.charAt(i);
            dfs(count + 1, chars, resultChar, list);
        }
    }
}
